set more off
clear all

cap log close
log using an_ipuse_stat,t replace

*** Some statistics on the ENIA-IP sample for 1995-2005
*** BHH June 2017, August 2019

use sample, clear

gen enia = totrev~=.
keep if enia
*** Drop Innovacion survey variables
drop bar_* coop* ef_* rd_* n_* npat_* soc_* org_* *inno* 
sort id year

*** Table B-2, Figure 2
foreach x in tm pat design um {
  tab year foreign [iweight=napp_`x']
}

foreach var of varlist ip tm pat oth { 
  egen x = sum(`var'old),by(id)
  gen `var'type = x>0
  egen xx = sum(`var'new),by(id)
  replace `var'type = 2 if xx
  drop x xx
}

drop first*
sort id year
gen first = id~=id[_n-1]
gen last = id~=id[_n+1]
tab year first

*** Table 2
tab ind iptype if first
tab ind tmtype if first
tab ind pattype if first

*** Table B-3
tab ind first 
tab ind last [iweight=employ]
tab ngap first, column

*** Table B-2
gen n = 1
collapse (sum) n tm pat dtm dpat napp*,by(year foreign)
list n napp_tm napp_pat if ~foreign, clean compress noobs
list n napp_tm napp_pat if foreign, clean compress noobs
collapse (sum) n tm pat dtm dpat napp*,by(year)
list n tm pat dtm dpat, clean compress noobs

log close



